<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="com.example.simpleforum.model.User" %>
<%@ page import="com.example.simpleforum.model.User.Role" %>
<!DOCTYPE html>
<html>
<head>
    <title>极简论坛</title>
    <link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="container">
    <h1>欢迎来到极简论坛</h1>
    <div class="search-box">
        <form action="ForumSearchServlet" method="get">
            <input type="text" name="keyword" placeholder="搜索板块..." required>
            <button type="submit">搜索</button>
        </form>
    </div>
    <%
        Object user = session.getAttribute("user");
        if (user != null) {
    %>
    <p>欢迎您，<%= ((com.example.simpleforum.model.User)user).getUsername() %>！</p>
    <div class="actions">
        <a href="PostListServlet" class="btn">查看帖子</a>
        <a href="UserCenterServlet" class="btn">个人中心</a>
        <% 
            User currentUser = (User) session.getAttribute("user");
            if (currentUser != null && currentUser.getRole() == Role.main_admin) { 
        %>
        <a href="ForumListServlet" class="btn">板块管理</a>
        <% } %>
        <a href="LogoutServlet" class="btn">退出登录</a>
    </div>
    <% } else { %>
    <div class="actions">
        <a href="login.jsp" class="btn">登录</a>
        <a href="register.jsp" class="btn">注册</a>
    </div>
    <% } %>
</div>
</body>
</html>